libxenlight: fix segfault when domid_to_name returns NULL
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 15 Mar 2010 13:22:06 +0000 (13:22 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 15 Mar 2010 13:22:06 +0000 (13:22 +0000)
The function libxl_domid_to_name() can return NULL if the path
/local/domain/%d/name does not exist.  This causes a segfault if the
NULL name is later passed as a value to libxl_xs_writev().  I'm
hitting this making a call to libxl_device_vfb_add() from my graphical
switcher application.

This patch modifies xs_writev() and libxl_xs_writev() to skip NULL
values.

Signed-off-by: Eamon Walsh <ewalsh@tycho.nsa.gov>
tools/libxl/libxl_xshelp.c

index 3c065a067b69b3a91e7b2035e4e4325a0cd5dd33..66de589c368ee747f5b86fb7120874afaf5f29c2 100644 (file)
@@ -33,11 +33,11 @@ int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[])
 
     for (i = 0; kvs[i] != NULL; i += 2) {
         asprintf(&path, "%s/%s", dir, kvs[i]);
-        if (path) {
+        if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
             xs_write(xsh, t, path, kvs[i + 1], length);
-            free(path);
         }
+        free(path);
     }
     return 0;
 }
@@ -74,7 +74,7 @@ int libxl_xs_writev(struct libxl_ctx *ctx, xs_transaction_t t,
 
     for (i = 0; kvs[i] != NULL; i += 2) {
         path = libxl_sprintf(ctx, "%s/%s", dir, kvs[i]);
-        if (path) {
+        if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
             xs_write(ctx->xsh, t, path, kvs[i + 1], length);
         }